<template>
    <div class="editItem">
        <el-card>
            <!-- 返回按钮 -->
            <el-button type="info" size="small" icon="el-icon-arrow-left"
                @click="toItem">
                返回</el-button>
            <!-- 添加表单 -->
            <el-form size="small" class="addForm">
                <el-row :gutter="20">
                    <el-col :span="12">

                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">药品名称</span>
                            </span>
                            <el-input v-model="form.name" readOnly></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">型号</span>
                            </span>
                            <el-input v-model="form.model" readOnly></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">单位</span>
                            </span>
                            <el-input v-model="form.unitName" readOnly></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">备注</span>
                            </span>
                            <el-input readOnly v-model="form.remarks" type="textarea" :rows="5"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">药品编号</span>
                            </span>
                            <el-input readOnly v-model="form.drugId"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">单价</span>
                            </span>
                            <el-input readOnly v-model="form.price"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">数量</span>
                            </span>
                            <el-input v-model="form.num"></el-input>
                        </el-form-item>
                        
                    </el-col>
                </el-row>
                
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item>
                            <span slot="label">
                                <span class="labelText">上传图片</span>
                            </span>
                            <el-upload action="/" list-type="picture-card">
                                <i class="el-icon-plus"></i>
                            </el-upload>
                            <el-dialog>
                                <img width="100%" alt="">
                            </el-dialog>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item class="subBtn">
                    <el-button type="primary" @click="alterInfo">保存</el-button>
                    <el-button @click="toItem">取消</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script>
import Pagination from '@/components/Pagination'
export default {
    name: 'ItemEdit',
    components: {
        Pagination
    },
    data() {
        return {
            form: {
                "name": "消食片",//药品名称
                "drugId": 1,//药品编号
                "model": null,//型号
                "price": 20,//单价
                "num": 23,//数量
                "unitName": "盒",//单位
                "totalAmount": 460,//金额
                "remarks": "没有",//备注
                "createTime": "2023-02-20",//创建时间
                "status":'',//状态
                "img": '',
            },
            addForm: {
                type: '',
                state: '',
                num: 1,
                stock: 0,
                salesState: 'false'
            },
            stockDialogTableVisible: false,
            dialogTableVisible: false,
            //供应商数据
            supplierData: [
                {
                    id: 1,
                    type: '公海',
                    name: 'xxx',
                    state: '有效',
                    followDate: '',
                    stock: ''
                },
                {
                    id: 2,
                    type: '公海',
                    name: 'xxx',
                    state: '无效',
                    followDate: '',
                    stock: ''
                },
            ],
            //出库入库
            stockInputNum: 10,
        }
    },
    created(){
        console.log(this.$route.query.tableData);
        this.form=this.$route.query.tableData;
    },
    methods: {
        //返回上一级
        toItem() {//跳转到开药单
            this.$router.push({path:'/Diagnosis/Item',query:{patient:this.form.patient,id:this.$route.query.id}})
        },
        //保存修改
        alterInfo(){
            this.$axios({
                    method:'post',
                    url:`/diagnosis/diagnosisManagement/updateDiagnosisDrug?drugId=${this.form.drugId}&id=${this.form.id}&num=${this.form.num}`,
                    data:{
                        id:this.form.id,
                        drugId:this.form.drugId,
                        num:this.form.num,
                    }
                })
                .then(resp=>{
                    console.log(resp.data);
                    this.$router.push({path:'/Diagnosis/Item',query:{patient:this.form.patient,id:this.$route.query.id}})
                })
        },
        //获取点击的页码-------------------------------
        getPagination(page) {
            //   console.log('----',page);
            // this.currentPage = page;
            // if (this.searchStatus) {//点击了查询按钮---搜索数据---再点击分页
            //     //0-7  8 -15  page=1 2 3 
            //     console.log(page);
            //     this.tableData = this.listTotal.slice((page - 1) * 8, page * 8)
            //     return;
            // }
            //默认产品列表的分页功能
        },
        //库存数量------------修改-------
        addStock() {
            this.addForm.stock += this.stockInputNum;
            this.stockDialogTableVisible = false;
        },
        outStock() {
            if (this.addForm.stock < this.stockInputNum) {
                this.$message.warning('库存数量不足，请重新修改')
            } else {
                this.addForm.stock -= this.stockInputNum;
                this.stockDialogTableVisible = false;
            }

        }
    }
}
</script>

<style scoped>
.editItem {
    margin: 20px 5px 0;
}

.labelText {
    font-size: 14px;
    font-weight: 600;
    color: #000;
}

.subBtn {
    text-align: center;
}

.stockBtn {
    margin-top: 20px;
    text-align: center;
}

/* element样式修改 */
.sales {
    float: none;
}

.choose>>>.el-select {
    display: block;
}

.dateChoose>>>.el-date-editor {
    display: block;
    width: 100%;
}

.dateChoose>>>.el-input__prefix {
    top: 17px;
}

.choose>>>.el-select .el-input__suffix {
    top: 15px;
}
</style>